package ex.klmy.gov.module;

import ex.klmy.gov.bean.LeaderMail;
import ex.klmy.gov.bean.LeaderMailDetails;
import ex.klmy.gov.bean.NewsDetails;
import ex.klmy.gov.utils.StringUtils;
import org.nutz.dao.Cnd;
import org.nutz.ioc.annotation.InjectName;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

/**
 * Created by xiaguoqiang on 16/11/3.
 */
@IocBean
@InjectName
@At("/zmhd")
public class InteractionAction extends BaseAction{

    @At
    @Ok("jsonp")
    public Object getLeaderMails(int pageNo, int pageSize) {
        List<LeaderMail> l = basicDao.searchByPage(LeaderMail.class,Cnd.NEW().desc("wbdate"),pageNo,pageSize);
        return l;
    }

    @At
    @Ok("jsonp")
    public Object searchLeaderMails(@Param("key") String key,int pageNo, int pageSize) {
        List<LeaderMail> l = new ArrayList<>();
        if(StringUtils.isInteger(key)){
             l = basicDao.searchByPage(LeaderMail.class,Cnd.where("wbserialnum","=",key).desc("wbdate"),pageNo,pageSize);
        }else{
             l = basicDao.searchByPage(LeaderMail.class,Cnd.where("wbtitle","like","%" + key + "%").desc("wbdate"),pageNo,pageSize);
        }
        return l;
    }

    @At
    @Ok("jsonp")
    public Object getMailById(@Param("id") String mailid) {
        LeaderMailDetails n = basicDao.findByCondition(LeaderMailDetails.class, Cnd.wrap("where wbleadermailid = " + mailid));
        return n;
    }


}
